﻿using Utils;

namespace StockAnalyst2.Chart
{
	internal class DataManager : PropertyChangedNotifier
	{
		#region Attributes

		private readonly ChartData _model;

		private bool _isMainDataLoaded;
		private bool _isVolumeDataLoaded;
		private bool _isIndicatorsDataLoaded;
		private bool _isAnyDataLoaded;

		#endregion

		#region Properties

		public bool IsMainDataLoaded
		{
			get
			{
				return _isMainDataLoaded;
			}
			set
			{
				if (value != _isMainDataLoaded)
				{
					_isMainDataLoaded = value;
					base.OnPropertyChanged("IsMainDataLoaded");
				}
			}
		}

		public bool IsIndicatorsDataLoaded
		{
			get
			{
				return _isIndicatorsDataLoaded;
			}
			set
			{
				if (value != _isIndicatorsDataLoaded)
				{
					_isIndicatorsDataLoaded = value;
					base.OnPropertyChanged("IsIndicatorsDataLoaded");
				}
			}
		}

		public bool IsVolumeDataLoaded
		{
			get
			{
				return _isVolumeDataLoaded;
			}
			set
			{
				if (value != _isVolumeDataLoaded)
				{
					_isVolumeDataLoaded = value;
					base.OnPropertyChanged("IsVolumeDataLoaded");
				}
			}
		}

		public bool IsAnyDataLoaded
		{
			get
			{
				return _isAnyDataLoaded;
			}
			set
			{
				if (value != _isAnyDataLoaded)
				{
					_isAnyDataLoaded = value;
					base.OnPropertyChanged("IsAnyDataLoaded");
				}
			}
		}

		#endregion

		#region Public Methods

		public DataManager(ChartData model)
		{
			_model = model;
		}

		public void RefreshDataStatus()
		{
			this.IsMainDataLoaded = _model.LastValue.Data.Count > 0 || _model.BidAskAverage.Data.Count > 0;
			this.IsIndicatorsDataLoaded = _model.Stochastic.Data.Count > 0 || _model.Gap.Data.Count > 0;
			this.IsVolumeDataLoaded = _model.AverageVolume.Data.Count > 0 || _model.Volume.Data.Count > 0 || _model.TotalVolume.Data.Count > 0;
			this.IsAnyDataLoaded = this.IsMainDataLoaded || this.IsIndicatorsDataLoaded || this.IsVolumeDataLoaded;
		}

		#endregion
	}
}
